package com.mobilereports.view;

import java.util.LinkedList;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.ArrayAdapter;
import android.widget.ListView;

import com.mobilereports.R;
import com.mobilereports.model.Report;
import com.mobilereports.model.ReportColumn;

public class MobileReports extends Activity
{
	private ListView reportsListView;

	/** Called when the activity is first created. */
	@Override
	public void onCreate(Bundle savedInstanceState)
	{
		super.onCreate(savedInstanceState);
		setContentView(R.layout.main);

		reportsListView = (ListView) findViewById(R.id.reportsListView);
		reportsListView.setAdapter(new ArrayAdapter<Report>(this,
				android.R.layout.simple_list_item_1, GlobalState.reportService
						.getReports()));
		reportsListView.setOnItemClickListener(new OnItemClickListener()
		{

			@Override
			public void onItemClick(AdapterView<?> adapterView, View view,
					int position, long rowID)
			{
				GlobalState.report = (Report) adapterView
						.getItemAtPosition(position);

				GlobalState.allColumnsArrayAdapter = new ArrayAdapter<ReportColumn>(
						getApplicationContext(),
						android.R.layout.simple_list_item_1,
						new LinkedList<ReportColumn>());
				for (ReportColumn rc : GlobalState.reportService
						.getReportHierarchyColumns(GlobalState.report))
					GlobalState.allColumnsArrayAdapter.add(rc);
				
				GlobalState.selectedColumnsArrayAdapter = new ArrayAdapter<ReportColumn>(
						getApplicationContext(),
						android.R.layout.simple_list_item_1,
						new LinkedList<ReportColumn>());

				Intent intent = new Intent(view.getContext(),
						ColumnSelectionActivity.class);
				startActivity(intent);
			}
		});
	}
}